import os
import pytest
from config.config import MULTI_PROCESS
from utils.mysql_utils import execute_sql_file

if __name__ == "__main__":

    # 由于多进程模式下, 会多次初始化数据, 文件锁的实现方式过于繁琐, 这里用简单的实现方式, 手动执行初始化逻辑
    execute_sql_file('./config/destroy.sql', 'DESTROY')

    execute_sql_file('./config/init_warehouse_area.sql', 'INIT_WAREHOUSE_AREA')
    execute_sql_file('./config/init_item_type.sql', 'INIT_ITEM_TYPE')


    if MULTI_PROCESS:
        # 自动匹配进程数
        pytest.main(["-vs", "-nauto", "./testcases/test_runner.py", "--alluredir", "./report/json_report", "--clean-alluredir"])
    else:
        pytest.main(["-vs", "./testcases/test_runner.py", "--alluredir", "./report/json_report", "--clean-alluredir"])

    os.system("allure generate ./report/json_report -o ./report/html_report --clean")
